package com.sergiandreplace.kaboom.comic;

import java.util.ArrayList;

import android.graphics.Bitmap;

import com.sergiandreplace.kaboom.format.FormatManager.OnBitmapLoadedListener;
import com.sergiandreplace.kaboom.format.zip.ZipManager;
import com.sergiandreplace.kaboom.util.MyLog;

public class Comic implements OnBitmapLoadedListener
{
	private String uri = "";
	private ZipManager zipManager = null;
	private int pages;
	private ArrayList<PageThumbnail> pageThumbnails;
	private OnPageLoadedListener onPageLoadedListener;
	

	public Comic(String uri)
	{
		setUri(uri);

	}

	public void setUri(String uri)
	{
		this.uri = uri;
	}

	public String getUri()
	{
		return uri;
	}

	public void loadComicInfo()
	{
		zipManager = new ZipManager(uri);
		if (zipManager.loadFileInfo())
		{
			MyLog.l("Info loaded for " + uri);
			zipManager.loadFilenames(".*\\.jpe?g");
			setPages(zipManager.getFilenames());

		}
	}

	public void loadPage(int index, int size)
	{
		zipManager.setOnBitmapLoadedListener(this);
		zipManager.loadBitmap(index, size);

	}

	public void setPages(int pages)
	{
		this.pages = pages;
	}

	public int getPages()
	{
		return pages;
	}

	public void setPageThumbnails(ArrayList<PageThumbnail> pageThumbnails)
	{
		this.pageThumbnails = pageThumbnails;
	}

	public ArrayList<PageThumbnail> getPageThumbnails()
	{
		return pageThumbnails;
	}

	public void setOnPageLoadedListener(OnPageLoadedListener onPageLoadedListener)
	{
		this.onPageLoadedListener = onPageLoadedListener;
	}

	public OnPageLoadedListener getOnPageLoadedListener()
	{
		return onPageLoadedListener;
	}

	public interface OnPageLoadedListener
	{
		public void onBitmapLoaded(Bitmap thumb);
	}

	@Override
	public void onBitmapLoaded(Bitmap p)
	{

	
		if (onPageLoadedListener != null) onPageLoadedListener.onBitmapLoaded(p);

	}



}
